package safe_lru

import (
	"fmt"
	"sync"
	"testing"
	"time"
)

var set = make(map[int]struct{})

func printOnce(num int) {
	if _, exist := set[num]; !exist {
		fmt.Println(num)
	}
	set[num] = struct{}{}
}
func TestPrintOnce(t *testing.T) {
	for i := 0; i < 10; i++ {
		go printOnce(100)
	}
	time.Sleep(100000)
}

var mutex sync.Mutex

func syncMutexPrintOnce(num int) {
	mutex.Lock()
	defer mutex.Unlock()
	if _, exist := set[num]; !exist {
		fmt.Println(num)
	}
	set[num] = struct{}{}
}
func TestSyncMutex(t *testing.T) {
	for i := 0; i < 10; i++ {
		go syncMutexPrintOnce(100)
	}
	time.Sleep(100000)
}
